package com.azier.kapacitor.script.node;

import com.azier.kapacitor.script.arg.SingleQuotesArg;
import com.azier.kapacitor.script.method.*;
import com.azier.kapacitor.script.node.nodebind.CommonNodeBind;

import java.util.ArrayList;

/**
* 1 * @Author: luoj
* 2 * @Date: 2019/11/8 11:27
* 3
*/

/**
Creates an HTTP Post node that POSTS received data to the provided HTTP endpoint. HttpPost expects 0 or 1 arguments. If 0 arguments are provided, you must specify an endpoint property method.
**/
/**
创建一个HTTP Post节点，该节点将接收到的数据POSTS到提供的HTTP端点。 HttpPost需要0或1个参数。如果提供了0个参数，则必须指定一个端点属性方法。
**/
public class HttpPostNode extends AbstractNode implements CommonNodeBind {
    private static final String name = "httpPost";

    public HttpPostNode(String ...url) {
        super(new ArrayList<>(),new ArrayList<>(),name);
        //
        for(String argf : url){
        this.args.add(new SingleQuotesArg(argf));
        }
    }

    /**
    CaptureResponse indicates that the HTTP response should be read and logged if the status code was not an 2xx code.
    **/
    /**
    CaptureResponse指示如果状态代码不是2xx代码，则应读取并记录HTTP响应。
    **/
    public HttpPostNode captureResponse(){
        CaptureResponse captureResponse = new CaptureResponse();
        super.addMethod(captureResponse);
        return this;
    }
    /**
    CodeField is the name of the field in which to place the HTTP status code. If the HTTP request fails at a layer below HTTP, (i.e. rejected TCP connection), then the status code is set to 0.
    **/
    /**
    CodeField是放置HTTP状态代码的字段的名称。如果HTTP请求在HTTP之下的某个层失败（即TCP连接被拒绝），则状态码将设置为0。
    **/
    public HttpPostNode codeField(String httpPost){
        CodeField codeField = new CodeField(httpPost);
        super.addMethod(codeField);
        return this;
    }
    /**
    Name of the endpoint to be used, as is defined in the configuration file.
    **/
    /**
    要使用的端点的名称，如配置文件中所定义。
    **/
    public HttpPostNode endpoint(String endpoint){
        Endpoint endpointM = new Endpoint(endpoint);
        super.addMethod(endpointM);
        return this;
    }
    /**
    Add a header to the POST request
    **/
    /**
    将标题添加到POST请求
    **/
    public HttpPostNode header(String v, String k){
        Header header = new Header(v, k);
        super.addMethod(header);
        return this;
    }
    /**
    Suppress all error logging events from this node.
    **/
    /**
    禁止来自此节点的所有错误记录事件。
    **/
    public HttpPostNode quiet(){
        Quiet quiet = new Quiet();
        super.addMethod(quiet);
        return this;
    }
    /**
    Timeout for HTTP Post
    **/
    /**
    HTTP发布超时
    **/
    public HttpPostNode timeout(long interval, String durationLiteral){
        Timeout timeout = new Timeout(interval, durationLiteral);
        super.addMethod(timeout);
        return this;
    }
}